//
//  QSNotificationCenterController.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/3/19.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSNotificationCenterController.h"
#import "QSNotificationCenterCell.h"
#import "QSNotificationDetailsViewController.h"
#import "QSHomeInterface.h"
@interface QSNotificationCenterController ()<DZNEmptyDataSetSource, DZNEmptyDataSetDelegate>
@property (nonatomic, strong) NSMutableArray *noticeList;
@end
static NSString * const notoficationCell = @"NotoficationCell";

@implementation QSNotificationCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"消息通知";
    // Do any additional setup after loading the view.
    [self addRefreshHeader];
    [self addRefreshFooter];
    self.tableView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight - kNavgationBarHeight);
       self.tableView.backgroundColor = [UIColor QSColorGrayEEEEEE];
    self.view.backgroundColor = [UIColor QSColorWhiteFFFFFF];
//       [self.tableView registerClass:[QSEntrepreneurshipPolicyViewCell class] forCellReuseIdentifier:kEntrepreneurshipPolicyCell];
    [self.tableView registerNib:[UINib nibWithNibName:@"QSNotificationCenterCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:notoficationCell];
    [self.dataArray addObject:@"1"];
    [self startRefreshing];
    
    
}


- (void)tableViewShouldUpdateDataByPageIndex:(NSInteger)pageIndex{
    NSLog(@"加载中...");
    [QSHomeInterface getNotificationListWithPageIndex:pageIndex andBlock:^(ResponseMessage * _Nonnull rspStatusAndMessage, QSNotificationModel * _Nonnull resultModel) {
        if (rspStatusAndMessage.code == kResponseSuccessCode) {
            if (pageIndex == 1) {
                [self.noticeList removeAllObjects];
            }
            [self.noticeList addObjectsFromArray:resultModel.list];
            self.tableView.emptyDataSetSource = self;
            self.tableView.emptyDataSetDelegate = self;
            [self.tableView reloadData];
            [self.tableView qs_endRefreshing];
            if (resultModel.pages >= pageIndex) {
                self.tableView.mj_footer.hidden = YES;
                [self endRefreshingWithNoMoreData];
            }else{
                self.tableView.mj_footer.hidden = NO;
            }
            
            NSLog(@"通知数组%@", resultModel.list);
//            self.noticeList = resultModel.list.mutableCopy;
//            if (self.noticeList.count == 0) {
//                self.noticeList = @[@"关于浙江省环境保护督察反馈问题整改完成情况的公示", @"2018年度婺城区区级工业经济项目补助资金公示", @"关于组织申报2018年度区级两化融合项目验收及资金补助工作的通知"].mutableCopy;
//            }
        }
    }];
 
}

#pragma mark -
- (NSMutableArray *)noticeList{
    if (!_noticeList) {
        _noticeList = [NSMutableArray array];
    }
    return _noticeList;
}

#pragma mark - **************** UITableView Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.noticeList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    QSNotificationCenterCell *cell = [tableView dequeueReusableCellWithIdentifier:notoficationCell forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.model =  self.noticeList[indexPath.row];
    return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return kRealValue(80 + 10);//cell间距
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    DLog(@"点击了第%ld个cell",indexPath.row);
    QSNotificationDetailModel *model = self.noticeList[indexPath.row];
    QSNotificationDetailsViewController *vc = [QSNotificationDetailsViewController new];
    NSLog(@"%ld", model.imId);
    vc.imId = model.imId;
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - DZNEmptyDataSetSource
/**
 *  返回标题文字
 */
- (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
{
    NSString *text = @"暂无消息通知!";
    NSDictionary *attributes = @{ NSFontAttributeName: [UIFont boldSystemFontOfSize:14.0f],
                                     NSForegroundColorAttributeName: [UIColor QSColorBlack666666] };
    return [[NSAttributedString alloc]initWithString:text attributes:attributes];
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView {
    scrollView.backgroundColor = [UIColor QSColorWhiteFFFFFF];
    return [UIImage imageNamed:@"ic_nullimage"];
}

- (void)getNotificationListWith{
    
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
